<?php

if (!defined('PUBLIC_HTML'))
{
	exit;
}

$menu_id	= (isset($_GET['id'])) 		? (is_numeric($_GET['id']) ? intval($_GET['id']) : 0) : 0;
$submit		= (isset($_POST['submit'])) ? true : false;
$page_title = 'Edit Menu Item';

if ($menu_id == 0 || !$database->sqlCount(TABLE_MENU, 'men_id', $menu_id) == 1)
{
	if (!$ajax)
	{
		redirect('cms.php?p=menu');
	}
	exit;
}

$get_menu =	"
			SELECT		*
			FROM		" . TABLE_MENU . "
			WHERE		men_id = '" . $menu_id . "'
			LIMIT		0, 1
			";
$database->query($get_menu);
$row_menu = $database->single();

$tpl_vars['MENU_ID']		= (int)		$row_menu['men_id'];
$tpl_vars['MENU_TITLE']		= (string)	$row_menu['men_title'];
$tpl_vars['MENU_TARGET']	= (string)	$row_menu['men_target'];
$tpl_vars['MENU_LINK']		= (string)	$row_menu['men_link'];
$tpl_vars['MENU_WINDOW_SELF']	= ((string) $row_menu['men_target'] == '_self') ? ' selected="selected"' : '';
$tpl_vars['MENU_WINDOW_BLANK']	= ((string) $row_menu['men_target'] == '_blank') ? ' selected="selected"' : '';

if ($submit)
{
	$post = array();
	$post['page_id']	= (isset($_POST['page_id']))	? (int) $string->secure($_POST['page_id'], 'sql_single_field') : (int) 0;
	$post['link']		= (isset($_POST['link']))		? ((!empty($_POST['link']))		? (string) $string->secure($_POST['link'],		'sql_single_field') : '') 			: '';
	$post['target']		= (isset($_POST['target']))		? ((!empty($_POST['target']))	? (string) $string->secure($_POST['target'],	'sql_single_field') : '_self') 		: '_self';
	$post['title']		= (isset($_POST['title']))		? ((!empty($_POST['title']))	? (string) $string->secure($_POST['title'],		'sql_single_field') : 'undefined') 	: 'undefined';
	$post['lang']		= (isset($_POST['language']))	? ((!empty($_POST['language'])) ? (string) $string->secure($_POST['language'],	'sql_single_field') : 'en') 		: 'en';
	$db->sqlUpdate(TABLE_MENU, $post, 'men_id', $menu_id, 'men_');
	if (!$ajax)
	{
		redirect('cms.php?p=menu');
	}
	exit;
}

?>